package edu.zut.hb.ambition.report.spring.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import common.annotation.Log;
import common.core.controller.BaseController;
import common.core.domain.AjaxResult;
import common.enums.BusinessType;
import common.utils.poi.ExcelUtil;
import common.core.page.TableDataInfo;


@RestController
@RequestMapping("/system/report")
public class ReportController extends BaseController
{
    @Autowired
    private IReportService reportService;


    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(Report report)
    {
        startPage();
        List<Report> list = reportService.selectReportList(report);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "门诊挂号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Report report)
    {
        List<Report> list = reportService.selectReportList(report);
        ExcelUtil<Report> util = new ExcelUtil<Report>(Report.class);
        util.exportExcel(response, list, "门诊挂号数据");
    }


    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{reportid}")
    public AjaxResult getInfo(@PathVariable("reportid") Long reportid)
    {
        return AjaxResult.success(reportService.selectReportByReportid(reportid));
    }


    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "门诊挂号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Report report)
    {
        return toAjax(reportService.insertReport(report));
    }


    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "门诊挂号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Report report)
    {
        return toAjax(reportService.updateReport(report));
    }

    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "门诊挂号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportids}")
    public AjaxResult remove(@PathVariable Long[] reportids)
    {
        return toAjax(reportService.deleteReportByReportids(reportids));
    }
}
